import excel "~Clinton\clinton anonymous_3 october 2017.xlsx", sheet("Dissertation+Plan+B_October+4%2") firstrow

foreach var of varlist l1-l7 c1-c7 t1-t7{
	gen `var'2 = .
	replace `var'2 = 0 if `var' == "Strongly agree"
	replace `var'2 = 0 if `var' == "Strongly Agree"
	replace `var'2 = 1 if `var' == "Agree"
	replace `var'2 = 2 if `var' == "Neither agree nor disagree"
	replace `var'2 = 2 if `var' == "Neither Agree nor disagree"
	replace `var'2 = 3 if `var' == "Disagree"
	replace `var'2 = 4 if `var' == "Strongly disagree"
	replace `var'2 = 4 if `var' == "Strongly Disagree"
}
*

alpha l12-l72
factor l12-l72, ipf factor(1)
rotate, promax
predict preLegit

alpha c12-c72
factor c12-c72, ipf factor(1)
rotate, promax
predict postControl

alpha t12-t72
factor t12-t72, ipf factor(1)
rotate, promax
predict postTreatment

*** coded such that higher values 
*** indicate an increase in support
gen controlLegit = postControl - preLegit 
gen treatLegit = postTreatment - preLegit 
egen diffLegit = rowmean(controlLegit treatLegit)

*keep controlLegit treatLegit
*saveold "/Users/milesarmaly/Dropbox/Miles School Stuff/Research Stuff/0Active Solo Projects/Extra judicial Actors/Replication Materials/Figures/forDensityFig.dta", version(12)

gen treatmentDum = .
replace treatmentDum = 0 if postControl != .
replace treatmentDum = 1 if postTreatment != .

label define treatmentDum 0 "Control" 1 "Treated"
label values treatmentDum treatmentDum


reg diffLegit c.clinton##treatmentDum

margins, at(clinton = (0(1)100) treatment = (0))
margins, at(clinton = (0(1)100) treatment = (1))









foreach var of varlist scideo1 scideo2{
	gen `var'2 = .
	replace `var'2 = 1 if `var' == "Very liberal"
	replace `var'2 = 2 if `var' == "Somewhat liberal"
	replace `var'2 = 3 if `var' == "Moderate"
	replace `var'2 = 4 if `var' == "Somewhat conservative"
	replace `var'2 = 5 if `var' == "Very conservative"
}
*

gen ideology = .
replace ideology = 1 if self == "Extremely liberal"
replace ideology = 2 if self == "Liberal"
replace ideology = 2 if self == "Slightly liberal"
replace ideology = 3 if self == "Moderate"
replace ideology = 4 if self == "Slightly conservative"
replace ideology = 4 if self == "Conservative"
replace ideology = 5 if self == "Extremely conservative"


gen preIdeoDiff = 0
replace preIdeoDiff = 1 if scideo12 ==1 & ideology ==2 
replace preIdeoDiff = 1 if scideo12 ==2 & ideology ==1 
replace preIdeoDiff = 1 if scideo12 ==2 & ideology ==3 
replace preIdeoDiff = 1 if scideo12 ==3 & ideology ==2 
replace preIdeoDiff = 1 if scideo12 ==3 & ideology ==4 
replace preIdeoDiff = 1 if scideo12 ==4 & ideology ==3 
replace preIdeoDiff = 1 if scideo12 ==4 & ideology ==5 
replace preIdeoDiff = 1 if scideo12 ==5 & ideology ==4 

replace preIdeoDiff = 2 if scideo12 ==1 & ideology ==3 
replace preIdeoDiff = 2 if scideo12 ==2 & ideology ==4 
replace preIdeoDiff = 2 if scideo12 ==3 & ideology == 1
replace preIdeoDiff = 2 if scideo12 ==3 & ideology == 5
replace preIdeoDiff = 2 if scideo12 ==4 & ideology ==2 
replace preIdeoDiff = 2 if scideo12 ==5 & ideology ==3

replace preIdeoDiff = 3 if scideo12 ==1 & ideology ==4 
replace preIdeoDiff = 3 if scideo12 ==2 & ideology ==5 
replace preIdeoDiff = 3 if scideo12 ==4 & ideology ==1 
replace preIdeoDiff = 3 if scideo12 ==5 & ideology ==2

replace preIdeoDiff = 4 if scideo12 == 1& ideology ==5 
replace preIdeoDiff = 4 if scideo12 ==5 & ideology == 1  




gen postIdeoDiff = 0
replace postIdeoDiff = 1 if scideo22 ==1 & ideology ==2 
replace postIdeoDiff = 1 if scideo22 ==2 & ideology ==1 
replace postIdeoDiff = 1 if scideo22 ==2 & ideology ==3 
replace postIdeoDiff = 1 if scideo22 ==3 & ideology ==2 
replace postIdeoDiff = 1 if scideo22 ==3 & ideology ==4 
replace postIdeoDiff = 1 if scideo22 ==4 & ideology ==3 
replace postIdeoDiff = 1 if scideo22 ==4 & ideology ==5 
replace postIdeoDiff = 1 if scideo22 ==5 & ideology ==4 

replace postIdeoDiff = 2 if scideo22 ==1 & ideology ==3 
replace postIdeoDiff = 2 if scideo22 ==2 & ideology ==4 
replace postIdeoDiff = 2 if scideo22 ==3 & ideology == 1
replace postIdeoDiff = 2 if scideo22 ==3 & ideology == 5
replace postIdeoDiff = 2 if scideo22 ==4 & ideology ==2 
replace postIdeoDiff = 2 if scideo22 ==5 & ideology ==3

replace postIdeoDiff = 3 if scideo22 ==1 & ideology ==4 
replace postIdeoDiff = 3 if scideo22 ==2 & ideology ==5 
replace postIdeoDiff = 3 if scideo22 ==4 & ideology ==1 
replace postIdeoDiff = 3 if scideo22 ==5 & ideology ==2

replace postIdeoDiff = 4 if scideo22 == 1& ideology ==5 
replace postIdeoDiff = 4 if scideo22 ==5 & ideology == 1  

*** coded such that larger values indicate
*** that the difference has grown, and 
*** smaller values indicate the distance between
*** oneself and the perceived position of the Court
*** has shrunk
gen ideoDiff = postIdeoDiff - preIdeoDiff


reg treatLegit clinton ideoDiff, beta



margins, at(clinton = (0(1)100)) atmeans
margins, at(ideoDiff = (-4(1)4))
